<%@ page language="java" contentType="text/html; charset=utf-8" %>
<%@ page import="java.util.*" %>
<%@ page import="net.zdsoft.keel.util.StringUtils" %>
<%@ page import="net.zdsoft.wpchat.support.util.PageUtils" %>
<%@ page import="net.zdsoft.wpchat.support.action.advanced.LogAction" %>
<%
LogAction action = (LogAction) PageUtils.getAction();
Map<String,String> logger2LevelMap = action.getLogger2LevelMap();
String[] allLevels = action.getAllLevels();
String loggerNameKeyword = StringUtils.htmlFilterToEmpty(action.getLoggerNameKeyword());
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN" xml:lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css" media="all">@import url("../../css/style.css");</style>
<script type="text/javascript" language="javascript" src="../../script/sort.js"></script>
<script language="JavaScript" type="text/javascript">
<!--
function modifyLoggerLevel(loggerName) {
  if (loggerName == "") {
    return;
  }

  var span1 = document.getElementById(loggerName + "Span1");
  var span2 = document.getElementById(loggerName + "Span2");

  if (span1.style.display == "block") {
	var spans = document.getElementsByTagName("span");
    for (var i = 0; i < spans.length; i++) {
      if (spans[i].id.indexOf("Span1") != -1) {
        spans[i].style.display = "block";
      }
      else if (spans[i].id.indexOf("Span2") != -1) {
        spans[i].style.display = "none";
      }
    }

    span1.style.display = "none";
    span2.style.display = "block";
    return;
  }
}

function saveLoggerLevel(loggerName) {
  if (loggerName == "") {
    return;
  }

  var span1 = document.getElementById(loggerName + "Span1");
  if (span1.style.display == "block") {
    modifyLoggerLevel(loggerName);
    return;
  }
  var loggerNameKeyword = document.loggerForm.loggerNameKeyword.value;
  var level = document.getElementById(loggerName + "Level").value;
  location.href = "modifyLoggerLevel.htm?loggerName=" + loggerName
    + "&level=" + level + "&loggerNameKeyword=" + loggerNameKeyword;
}
//-->
</script>
</head>
<body>
<div id="tableMain">
  <div id="message"><%=PageUtils.errors(action)%><%=PageUtils.successMessage("日志级别修改成功！")%></div>
  <div id="condition">
    <form name="loggerForm" action="loggerList.htm" method="get">
	日志名称: 
	  <input id="loggerNameKeyword" name="loggerNameKeyword" type="text" value="<%=loggerNameKeyword%>" />
	  <input type="submit" name="submit" value=" 查询 " class="colorButton"/>
	</form>
  </div>
  <table id="dataTable" border="0" align="center" cellpadding="5" cellspacing="1">
    <tr style="cursor:hand" class="titleTr">
      <td width="70%">日志名称</td>
      <td align="center" width="15%">日志级别</td>
      <td align="center" width="15%">操作</td>
    </tr>
    <tbody><% 
for (Map.Entry<String, String> entry : logger2LevelMap.entrySet()){
  String loggerName = entry.getKey();
  String level = entry.getValue(); %>
    <tr>
      <td height="20"><%=loggerName%></td>
      <td align="center" style="cursor:hand" onclick="modifyLoggerLevel('<%=loggerName%>')">
        <span id="<%=loggerName%>Span1" style="display:block"><%=level%></span>
        <span id="<%=loggerName%>Span2" style="display:none">
          <select id="<%=loggerName%>Level" name="level"><%
  for (int i = 0; i < allLevels.length; i++) {
    String selected = allLevels[i].equals(level) ? " selected" : ""; %>
            <option value="<%=allLevels[i]%>"<%=selected%>><%=allLevels[i]%></option><%
  } %>
          </select>
        </span>
      </td>
      <td align="center"><a href="javascript:saveLoggerLevel('<%=loggerName%>')">修改</a></td>
    </tr><%
} %>
</tbody>
</table>
</div>
</body>
</html>
